home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Open Prolog 1.0.3d33 / External Predicates… / Sources / OpenPrologMultipleChoice.p < prev    next >
Text File  |  1995-11-10  |  6KB  |  162 lines

  1. {$D+} { MacsBug symbols on }
  2. {$R+} { No range checking }
  3.  
  4. UNIT OpenPrologDialogs;
  5.  
  6.   INTERFACE
  7.  
  8.     USES quickdraw, standardFile, TextUtils,
  9.          prlxdefinitions, prlxLibraries, traps, gestaltEqu;
  10.  
  11.     PROCEDURE entrypoint(plist: prlxptr);
  12.  
  13.   IMPLEMENTATION
  14.  
  15.         CONST
  16.       kMCBase = 154;
  17.       kMCDLOG = kMCBase;
  18.       kMCDITL = kMCBase;
  19.  
  20.     PROCEDURE main(plist: prlxptr);
  21.       FORWARD;
  22.  
  23.     PROCEDURE entrypoint(plist: prlxptr);
  24.  
  25.       BEGIN
  26.         main(plist);
  27.       END;
  28.  
  29.     PROCEDURE main;
  30.  
  31.       VAR
  32.         theOldPort: grafPtr;
  33.         theHandle: handle;
  34.         i, j: integer;
  35.         theRect: rect;
  36.  
  37.       PROCEDURE checkOSErr(hostErrorCode: osErr;
  38.                            errorKind, argumentIndex: longint;
  39.                            s: Str255);
  40.  
  41.         BEGIN
  42.           IF hostErrorCode <> noErr THEN
  43.             BEGIN
  44.             signalError(errorKind, argumentIndex, hostErrorCode, s, plist);
  45.             exit(main);
  46.             END;
  47.         END;
  48.  
  49.       BEGIN
  50.         WITH plist^ DO
  51.           BEGIN
  52.           outcome := noErrorSucceed;
  53.           determinate := true;
  54.           CASE request OF
  55.             getPRLXInfo:
  56.               BEGIN
  57.               data[1] := 1; {number of predicates defined}
  58.               data[2] := eventsVersion;
  59.               data[3] := 0
  60.               END;
  61.             initialisepredicate:
  62.               CASE id OF
  63.                 1:
  64.                   BEGIN
  65.                   s := 'system$multiple$choice'; {name}
  66.                   data[1] := 15;
  67. {Name,Prompt,OKtext,CancelText,ReplyText,Text1,Reply1,Text2,Reply2,Text3,Reply3
  68. Text4,Reply4,Text5,Reply5}
  69.                   END;
  70.                 OTHERWISE
  71.                   signalError(implementationError, - 1, 0,
  72.                               'predicate index out of range at initialise',
  73.                               plist);
  74.               END;
  75.             callpredicate:
  76.               CASE id OF
  77.                 1:
  78.                   WITH plist^ DO
  79.                     BEGIN
  80.                     dialogPtr(data[2]) := getNewDialog(kMCDLOG, NIL,
  81.                                                        windowPtr( - 1));
  82.                     IF dialogPtr(data[2]) <> NIL THEN
  83.                       BEGIN
  84.                       getPort(theOldPort);
  85.                       setPort(dialogPtr(data[2]));
  86.                       {window name}
  87.                       setWTitle(dialogPtr(data[2]), text(1, plist));
  88.                       {prompt}
  89.                       getDItem(dialogPtr(data[2]), 3, j, theHandle, theRect);
  90.                       setIText(theHandle, textOfAtomicList(2, plist));
  91.                       {default button}
  92.                       getDItem(dialogPtr(data[2]), 1, j, theHandle, theRect);
  93.                       IF text(3, plist) = '' THEN
  94.                         setCTitle(controlHandle(theHandle), 'OK')
  95.                       ELSE
  96.                         setCTitle(controlHandle(theHandle), text(3, plist));
  97.                       {cancel button}
  98.                       getDItem(dialogPtr(data[2]), 2, j, theHandle, theRect);
  99.                       IF text(4, plist) = '' THEN
  100.                         hideControl(controlHandle(theHandle))
  101.                       ELSE
  102.                         BEGIN
  103.                         setCTitle(controlHandle(theHandle), text(4, plist));
  104.                         showControl(controlHandle(theHandle));
  105.                         END;
  106.                       {multiple choices}
  107.                       FOR i := 5 TO 9 DO
  108.                         BEGIN
  109.                         IF text(i * 2 - 4, plist) = '[]' THEN
  110.                           BEGIN
  111.                           hideDItem(dialogPtr(data[2]),i);
  112.                           hideDItem(dialogPtr(data[2]),i+5);
  113.                           END
  114.                         ELSE
  115.                                                 begin
  116.                                                     getDItem(dialogPtr(data[2]), i, j, theHandle, theRect);
  117.                           setIText(theHandle, textOfAtomicList(i * 2 - 4,
  118.                                    plist));
  119.                                                 end;
  120.                         END;
  121.                       showWindow(dialogPtr(data[2]));
  122.                       openPrologDialogFilter(i,plist);
  123.                       {return text of button pressed}
  124.                       getDItem(dialogPtr(data[2]), i, j, theHandle, theRect);
  125.                       getCTitle(controlHandle(theHandle), s);
  126.                       successful := returnAtom(5, s, plist);
  127.                       FOR i := 10 TO 14 DO
  128.                         BEGIN
  129.                         getDItem(dialogPtr(data[2]), i, j, theHandle, theRect);
  130.                         getIText(theHandle, s);
  131.                         successful := successful AND returnString(i * 2 - 13, s,
  132.                                       plist);
  133.                         END;
  134.                       setPort(theOldPort);
  135.                                             disposeDialog(dialogPtr(data[2]));
  136.                       END; {if dialogPtr<>nil}
  137.                     END; {with}
  138.                 OTHERWISE
  139.                   signalError(implementationError, - 1, 0,
  140.                               'predicate index out of range at callPredicate',
  141.                               plist);
  142.               END; {case}
  143.             closepredicate:
  144.               BEGIN
  145.               CASE id OF
  146.                 1: ;
  147.                 2: ;
  148.                 OTHERWISE
  149.                   signalError(implementationError, - 1, 0,
  150.                               'predicate index out of range at closePredicate',
  151.                               plist);
  152.               END;
  153.               END;
  154.             OTHERWISE
  155.               signalError(implementationError, - 1, 0,
  156.                     'unknown call to OpenPrologDialogs external predicate suite'
  157.                           , plist);
  158.           END;
  159.           END;
  160.       END;
  161. END.
  162.